package com.xyht.sca_s.student_manage_system.modules.patrol.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.patrol.entity.vo.SmsPatrolVO;
import com.xyht.sca_s.student_manage_system.modules.patrol.service.SmsPatrolService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-04-09
 */

@RestController
@RequestMapping("/patrol/smsPatrol")
@SecretBody//解密
public class SmsPatrolController {
    @Autowired
    SmsPatrolService smsPatrolService;
    @Autowired
    JwtTokenUtil jwtTokenUtil;
    @ApiOperation("新增巡查记录")
    @PostMapping("/smsPatrolAdd")
    public ResponseResult smsPatrolAdd(@RequestBody SmsPatrolVO smsPatrol,HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsPatrolService.smsPatrolAdd(smsPatrol,user_id);
    }

    @ApiOperation("删除巡查记录")
    @DeleteMapping("/deleteSmsPatrol")
    public ResponseResult deleteSmsPatrol(@RequestBody SmsPatrolVO smsPatrol) {
        return smsPatrolService.deleteSmsPatrol(smsPatrol);
    }

    @ApiOperation("修改巡查记录")
    @PostMapping("/updateSmsPatrol")
    public ResponseResult updateSmsPatrol(@RequestBody SmsPatrolVO smsPatrol) {
        return smsPatrolService.updateSmsPatrol(smsPatrol);
    }

    @ApiOperation("前台查询巡查记录")
    @GetMapping("/selectSmsPatrol")
    public ResponseResult selectSmsPatrol(@RequestParam(value = "search_str", required = false) String search_str,
                                          @RequestParam(value = "name", required = false) String name,
                                          @RequestParam(value = "point", required = false) String point,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "bg_date", required = false) String bg_date,
                                          @RequestParam(value = "end_date", required = false) String end_date) {
        return smsPatrolService.selectSmsPatrol(search_str, name,point,pageSize, pageNum, bg_date, end_date);
    }

    @ApiOperation("后台查询巡查记录")
    @GetMapping("/selectSmsPatrolByHt")
    public ResponseResult selectSmsPatrolByHt(@RequestParam(value = "search_str", required = false) String search_str,
                                          @RequestParam(value = "status",required = false) Integer status,
                                          @RequestParam(value = "name", required = false) String name,
                                          @RequestParam(value = "point", required = false) String point,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "bg_date", required = false) String bg_date,
                                          @RequestParam(value = "end_date", required = false) String end_date) {
        return smsPatrolService.selectSmsPatrolByHt(search_str, status,name,point,pageSize, pageNum, bg_date, end_date);
    }

    @ApiOperation("根据ID查询巡查详情")
    @GetMapping("/selectSmsPatrolById")
    public ResponseResult selectSmsPatrolById(@RequestParam(value = "id", required = false) String id
                                          ) {
        return smsPatrolService.selectSmsPatrolById(id);
    }

    @ApiOperation("二维码")
    @PostMapping("/scanQr")
    public ResponseResult scanQr(@RequestBody SmsPatrolVO smsPatrolVO,
                                 HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsPatrolService.scanQr(smsPatrolVO,user_id);
    }






}

